package models.services;

import java.io.File;
import java.sql.Connection;
import java.util.HashMap;

import org.apache.log4j.Logger;

import models.services.utils.DBManager;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;

public class ServicioReportes {

	private final static Logger logger = Logger
			.getLogger(ServicioReportes.class);

	public void showReport(String nombreReporte, HashMap parametros) {
		try {
			String ruta = "src/models/services/reports/";
			JasperDesign design = JRXmlLoader.load(new File(ruta
					+ nombreReporte));
			Connection conexion = DBManager.getInstance().obtenerConnection();
			JasperReport compileReport = JasperCompileManager
					.compileReport(design);
			JasperPrint print = JasperFillManager.fillReport(compileReport,
					parametros, conexion);
			JasperViewer.viewReport(print);

		} catch (Exception e) {
			logger.error(e.getCause(), e);
		}
	}

}
